package com.ngo.web.interceptor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


@Component
public class LoginIntercept implements HandlerInterceptor {
	
	private static final Logger log = LoggerFactory.getLogger(LoginIntercept.class);

	@Override
	public void afterCompletion(HttpServletRequest arg0,
			HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
	}

	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
			Object arg2, ModelAndView arg3) throws Exception {
//		SessionUtils.clear();
	}

	@Override
	public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1,
			Object arg2) throws Exception {
		
		HttpSession session = arg0.getSession();
		String sessionId = session.getId();
		log.info("当前sessionId={}", sessionId);

//		UserDetailVO sessionUser = (UserDetailVO) session.getAttribute(SessionUtils.USER_KEY);
//		if (sessionUser != null && StringUtils.isNotEmpty(sessionUser.getUserid())) {
//			log.info("当前用户信息: {}", JSON.toJSONString(sessionUser));
//			SessionUtils.bind(sessionUser);
//		} else {
//			log.error("未获取到当前登录的用户信息,sessionId={}", sessionId);
//		}

		return true;
	}

}
